package top.sqdpt.pt.statemachine.machine;

import top.sqdpt.pt.statemachine.action.PtSpringStateAction;
import top.sqdpt.pt.statemachine.builder.PtStateTranslateBuilder;
import top.sqdpt.pt.statemachine.event.PtStateEvent;
import top.sqdpt.pt.statemachine.translate.PtStateTranslate;

import java.util.ArrayList;
import java.util.List;

public class PtSpringStateMachine<S extends Enum<S>, E extends Enum<E>, M extends Enum<M>> extends PtStateMachine<S, E> {

    private final M machineType;
    private final List<PtSpringStateAction<S, E, M>> rawActions;

    public PtSpringStateMachine(M machineType, List<PtSpringStateAction<S, E, M>> rawActions) {
        this.machineType = machineType;
        this.rawActions = rawActions;
    }

    @Override
    public List<PtStateTranslate<S, E>> initMachine(PtStateTranslateBuilder<S, E> ptStateTranslateBuilder) {
        List<PtStateTranslate<S, E>> ptStateTranslates = new ArrayList<>();
        for (PtSpringStateAction<S, E, M> ptEasyStateAction : rawActions) {
            ptStateTranslates.add(new PtStateTranslate<>(ptEasyStateAction.getStartState(), ptEasyStateAction.getTargetState(), new PtStateEvent<>(ptEasyStateAction.getEvent(), ptEasyStateAction)));
        }
        return ptStateTranslates;
    }

    public M getMachineType() {
        return this.machineType;
    }

}
